package databases

import (
	"fmt"
	"os"
	"peilian-api/app/global/databases/tables"
	"peilian-api/app/global/variable"
)

func Migrate() {
	env := os.Getenv("ENV")
	if env == "" {
		return
	}
	if err := variable.DB.MySQL.SetupJoinTable(&tables.Career{}, "CusQuestions", &tables.CustomCareer{}); err != nil {
		fmt.Println(err.Error())
		return
	}
	if err := variable.DB.MySQL.SetupJoinTable(&tables.Criteria{}, "Questions", &tables.CriteriaRelation{}); err != nil {
		fmt.Println(err.Error())
		return
	}
	if err := variable.DB.MySQL.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(
		&tables.User{},
		&tables.UserLoginLog{},
		&tables.UserShareLog{},
		&tables.Career{},
		&tables.Session{},
		&tables.ScoreFeedBack{},
		&tables.Question{},
		&tables.RealQues{},
		&tables.MarginVideo{},

		&tables.Agent{},
		&tables.Constitute{},
		&tables.CommonConf{},
		&tables.UserUploadRecord{},
		&tables.OptionLog{},
		&tables.Vpdata{},
		&tables.FeedBack{},
		&tables.Roles{},

		&tables.SchoolPosition{},
		&tables.Experience{},
		&tables.LogCallback{},
		&tables.ReportVerbalTrick{},
		&tables.SpecialRecord{},
		&tables.Personality{},
		&tables.ResumeRecord{},

		&tables.YzItems{},
		&tables.YzTrade{},
		&tables.YzMessage{},
		&tables.Member{},
		&tables.MaskWords{},
		&tables.School{},
		&tables.Criteria{},
		&tables.CriteriaRelation{},
		&tables.CustomCareer{},
		&tables.Interview{},
		&tables.ApiLog{},
		&tables.SchoolPositionCompany{},
		&tables.City{},

		&tables.CustomLabel{},
		&tables.Profession{},
	); err != nil {
		panic(err)
	}
	_ = variable.DB.MySQL.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&tables.SpecialQuestion{})
}
